Ext.onReady(function () {
	Ext.Loader.setConfig({
	   enabled: true,
	   paths : {
	      'JRainbow.pages' : 'javascripts/pages'
	   }
	});

	var north = new Ext.Panel({
        id: 'north',
        autoWidth: true,
        heigth: 240,
        frame: true,
        region: 'north',
        html: '<div style="background-color:#157FCC;font-size:25px;">简单客户关系管理系统</div>'
    });
    var west = new JRainbow.common.LeftMenu({
        id: 'west',
        title: '菜单栏',
        width: 200,
        heigth: 'auto',
        split: true, //显示分隔条
        region: 'west',
        collapsible: true,
        listeners : {
			'itemclick' : function(view, record) {
				var leaf = record.get('leaf');
				if (leaf) {
					var code = record.raw.code;
					var text = record.raw.text;
					var tabs = center;
					var tab = Ext.getCmp(code);
					if(tab == null){
						var url = 'JRainbow.pages.'+code+'Panel';
						Ext.require([url],function(){
							tab = tabs.add(Ext.widget('panel', {  
								id : code,
		                        title: text,  
		                        closable: true,
		                        items : [{
		                        	xtype : code+'Panel',
		                        	title : text,
		                        	pageSize : 30
		                        }]
		                    })); 
							tabs.setActiveTab(tab);
						}); 
					}
					
                    tabs.setActiveTab(tab);  
				} 
			}
		} 
    });
    var center = new Ext.TabPanel({
        region: 'center',
        activeTab: 0,
        items: [{
            title: '主页',
            authHeight: true,
            closable: false,
            html: '主页内容'
        }]
    });

    var bar = new Ext.Toolbar({
        collapsible: true,
        border : false,
        items : [
            '<b>当前登陆用户:  &nbsp;&nbsp;&nbsp;部门:&nbsp;&nbsp;&nbsp; 角色:&nbsp;&nbsp;&nbsp;</b>',
            '->', '主题风格：', {
                xtype : 'combo',
                store : new Ext.data.SimpleStore({
                    fields : ['text', 'value'],
                    data : [['默认风格', 'ext-all-neptune.css'],
                        ['经典风格', 'ext-all-classic.css'],
                        ['黑灰风格', 'ext-all-gray.css']]
                }),
                mode : 'local',
                triggerAction : 'all',
                valueField : 'value',
                displayField : 'text',
                hiddenName : 'theme',
                name : 'theme',
                value : '默认风格',
                editable : false,
                listeners : {
                    'select' : function(theme) {
                        var date = new Date();
                        date.setTime(date.getTime() + 30 * 3600000);
                        Ext.util.CSS.swapStyleSheet('theme',
                                '/extjs/resources/css/' + theme.value);
                    }
                }
            }, '-', {
                text : '修改密码',
                iconCls : 'resetpas',
                handler : function() {

                }
            }, '-', {
                text : '注 销',
                iconCls : 'logout',
                tooltip : '',
                handler : function() {
                    Ext.MessageBox.confirm('信息', '您确认要退出系统吗?',
                        function(btn) {
                            if (btn == 'yes') {
                                window.location = '/logout';
                            }
                        });
                }
            }]
    });
    var south = new Ext.Panel({
        id: 'south',
        autoWidth: true,
        heigth: 65,
        frame: false,
        region: 'south',
        items : [bar]
    });

    var viewport = new Ext.Viewport({
        layout: "border",
        items: [north, south, west, center]
    });
});